<template>
  <div>
       <div class="shop_list">
            <div class="shop_item" v-for="(item,index) in list" :key="index" >
                <div class="shop_box">
                    <span @click="goInfo(item)">
                         <img :src="'http://www.baseco.top/ljm/public/uploads/shop/'+item.shop_img" alt="">
                    <span class="shop_price">¥{{item.shop_price}}</span>
                    <span class="shop_desc">{{item.shop_title}}{{item.shop_desc}}</span>
                    </span>
                    <span class="shop_join">加入购物车</span>
                </div>
            </div>  
        </div>  
         <div class="pageList">
             <page :page-index="page" :total="count" :page-size="pageSize" @change="pageChange"></page>
         </div>
  </div>
</template>

<script>
import {ljmAjax} from '@/api/index'
import Page from '@/components/page'
export default {
  data() {
    return {
        list:{},
        page:1,
        count:0,
        pageSize:12,
        searchVal:this.$route.query.key
    };
  },
  created () {
       this.init()
  },
  watch: {
   '$route'(){
      this.searchVal = this.$route.query.key
      this.init();
    }
  },
  methods: {
      init(){
         const data = {
            key:this.searchVal,
            page:this.page,
            pageSize:this.pageSize
        }
      ljmAjax('api/index/search',data).then(res=>{
          this.list = res.data.data
          this.count = res.data.total  
        }) 
      },
      goInfo(item){
          console.log(item)
          this.$router.push('/info?id='+item.shop_id)
      },
      pageChange(page){
          this.page = page;
          this.init();
          console.log(page)
      }
  },





  
  components: {
      Page
  }
};
</script>
<style scoped>
.shop_list{
    display: flex;
    flex-wrap: wrap;
    width: 1200px;
    margin: 30px auto;
}
.shop_list .shop_item{
    width: 278px;
    height: 310px;
    margin-right: 20px;
    margin-bottom: 20px;
    border: 1px solid #f5f5f5;
    cursor: pointer;
    transition: all .2s;
}
.shop_list .shop_item:hover{
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    transform: translate3d(0, -2px, 0);
    border: 1px solid red;
}
.shop_item img{
    width: 265px;
    height: 186px;
    margin-top: 6px;
    margin-left: 6px;
}
.shop_item .shop_price{
    color: #e62318;
    font-weight: 500;
    height: 26px;
    display: block;
    padding-left: 10px;
    margin-top: 8px;
    overflow: hidden;
    white-space: nowrap;
}
.shop_item .shop_desc{
    height: 38px;
    line-height: 20px;
    color: #333;
    display: block;
    overflow: hidden;
    padding: 0 10px;
    margin-top: 4px;
}
.shop_item .shop_join{
    margin-top: 5px;
    margin-right: 10px;
    width: 100px;
    height: 25px;
    line-height: 25px;
    color: red;
    display: block;
    border: 1px solid #dedede;
    font-size: 14px;
    text-align: center;
    float: right;
    cursor: pointer;
}
.shop_item .shop_join:hover{
    border: 1px solid red;
}
.pageList{
        text-align: center;
}
</style>


